package com.fei.test;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import org.apache.pdfbox.rendering.PDFRenderer;

public class TransImageTask extends Thread {

    private int maxPage;

    private int currentPage;

    private String fileName;

    private PDFRenderer renderer;

    private String imgPath;

    public TransImageTask(int currentPage, int maxPage, String fileName,
            PDFRenderer renderer, String imgPath) {
        this.maxPage = maxPage;
        this.currentPage = currentPage;
        this.fileName = fileName;
        this.renderer = renderer;
        this.imgPath = imgPath;
    }

    @Override
    public void run() {

        try {
            for (int i = this.currentPage; i < maxPage; i++) {
                BufferedImage image = renderer.renderImageWithDPI(i, 450);

                String name = imgPath
                        + fileName.substring(0, fileName.lastIndexOf(".")) + "_"
                        + (i + 1) + ".jpg";
                ImageIO.write(image, "JPG", new File(name));
            }

        }
        catch (Exception e) {
            e.printStackTrace();

        }

    }

}
